/***********************************************************
 *
 * Gaoth
 * Copyright (c) 2011- Marcus Lundgren
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from
 * the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it freely,
 * subject to the following restrictions:
 *
 *  1. The origin of this software must not be misrepresented; you must not
 *     claim that you wrote the original software. If you use this software
 *     in a product, an acknowledgment in the product documentation would be
 *     appreciated but is not required.
 *
 *  2. Altered source versions must be plainly marked as such,
 *     and must not be misrepresented as being the original software.
 *
 *  3. This notice may not be removed or altered from any source distribution.
 *
 ***********************************************************/

#include "menu_state.h"

MenuState::MenuState( irr::IrrlichtDevice *window, irr::video::IVideoDriver *driver, irr::scene::ISceneManager *scene_man,
        irr::gui::IGUIEnvironment *gui_env, Model *model )
: IState( window, driver, scene_man, gui_env, model )
{
    _font = _gui_env->getFont("../resources/myfont.xml");

    _gui_env->addButton(irr::core::rect<irr::s32>(10,240,110,240 + 32), 0, GUI_ID_GAME_STATE_BUTTON,
            L"Game state!", L"herp");
    _gui_env->addButton(irr::core::rect<irr::s32>(10,280,110,280 + 32), 0, GUI_ID_QUIT_BUTTON,
            L"Quit", L"Exits Program");

    _window->setEventReceiver(this);
}

MenuState::~MenuState()
{

}

void MenuState::init()
{
    _is_done = false;
}

bool MenuState::OnEvent( const irr::SEvent& event )
{
    if (event.EventType == irr::EET_GUI_EVENT)
    {
        irr::s32 id = event.GUIEvent.Caller->getID();

        if( event.GUIEvent.EventType == irr::gui::EGET_BUTTON_CLICKED )
        {
            switch( id )
            {
                case GUI_ID_GAME_STATE_BUTTON:
                    _next_state = GAME_STATE;
                    _is_done = true;
                    return true;
                case GUI_ID_QUIT_BUTTON:
                    _next_state = END_STATE;
                    _is_done = true;
                    return true;
                default:
                    return false;
            }
        }
    }

    return false;
}

void MenuState::update( const float /*time*/ )
{

}

void MenuState::draw() const
{
    _driver->beginScene(true, true, irr::video::SColor(255,100,101,140));

    _font->draw(L"herpeliderp",
            irr::core::rect<irr::s32>(130,10,300,50),
            irr::video::SColor(255,255,255,255));

    //_scene_mgr->drawAll();
    _gui_env->drawAll();

    _driver->endScene();
}
